home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gwuada_8.zip
/
CWKGRAPH.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-29
|
25KB
|
935 lines
/*
GWMON Parallel Ada Monitor for 386/486 PCs
Copyright (C) 1993, Charles W. Kann & Michael Bliss Feldman
ckann@seas.gwu.edu mfeldman@seas.gwu.edu
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "ed.h"
#include "keydef.h"
#if 0
#define ROWS 10
#endif
static int ROWS = 10;
#define COLS 78
#define MAX_WINDOWS 12
static char video[4000];
static AVL_WIN_PTR top_win, output_win;
static struct rccoord text_pos;
static int next_monitor;
static int SAVE_WIN_SIZE;
/*
Structures for Block names for monitor windows titles. Note that the
Block names structure does not malloc the names. I was afraid that
malloc would fragment core too much with alot of funny sized pieces of
memory.
*/
#define MAX_LEVELS 200
#define NAME_SIZE 32
static char Block_Name[MAX_LEVELS][NAME_SIZE];
#define NEWLINE 0x0a
#define ESCAPE 0x1b
void CWK_DEL_WINDOW();
static struct {
AVL_WIN_PTR w;
int used;
COORD wind_coord;
int monitor;
} window[MAX_WINDOWS];
static int SCROLL_LINE = 0, escape_sequence = 0;
void CWK_ERASE_ALL_MON_WIN();
void CWK_ERASE_MON_WIN();
void CWK_CLEANUP_MON();
CWK_MOVE_INPUT( fp )
FILE *fp;
{
struct rccoord text_p;
if ( ! isatty( fileno(fp) ))
return;
text_p= _gettextposition();
text_p.col = 1;
text_p.row++;
if (text_p.row >= ROWS) {
SCROLL_LINE = 1;
text_p.row--;
}
_settextposition(text_p.row, text_p.col);
}
CWK_PUTC( inchar, fp )
int inchar;
FILE *fp;
{
struct rccoord text_p;
static int screen_row, screen_col;
static char next_char;
char TextString[2];
/*
if this file is not a tty, write the character and continue
*/
if ( ! isatty( fileno(fp) )) {
fputc(inchar,fp);fflush(fp);
return;
}
/*
Cheap kludge to handle ascii control sequences
*/
if ( escape_sequence ) {
switch ( next_char ) {
case '[' :
if ( inchar == '[' ) {
next_char = '1';
return;
}
break;
case '1' :
if ( inchar == 'J' ) {
int i;
char buf[80];
escape_sequence = 0;
sprintf(buf,"%-78s"," ");
for(i = 1; i <= ROWS; ++i) {
_settextposition(i, 1 );
_outtext(buf);
}
_settextposition(1, 1 );
return;
}
else if ( inchar == ';' ) {
next_char = '2';
return;
}
else if (isdigit( inchar )) {
screen_row = screen_row * 10 + (inchar - '0');
return;
}
break;
case '2' :
if ( inchar == 'f' ) {
escape_sequence = 0;
_settextposition(screen_row, screen_col);
return;
}
else if ( isdigit( inchar )) {
screen_col = screen_col * 10 + (inchar - '0');
return;
}
break;
default:
break;
}
escape_sequence = 0;
}
if ( inchar != ESCAPE ) {
text_p= _gettextposition();
if ( SCROLL_LINE ) {
_scrolltextwindow(_GSCROLLUP);
SCROLL_LINE = 0;
}
}
if ( inchar == ESCAPE ) {
SCROLL_LINE = 0;
escape_sequence = 1;
screen_row = screen_col = 0;
next_char = '[';
return;
}
else if ( ( inchar == NEWLINE ) || ( inchar == CTRL_M ) ) {
text_p.col = 1;
text_p.row++;
if (text_p.row >= ROWS) {
SCROLL_LINE = 1;
text_p.row--;
}
}
else {
sprintf( TextString, "%c", inchar );
_outtext( TextString );
text_p.col++;
if ( text_p.col > COLS ) {
text_p.col = 1;
text_p.row++;
}
}
if (text_p.row >= ROWS) {
SCROLL_LINE = 1;
text_p.row--;
}
_settextposition(text_p.row, text_p.col);
}
static int CWK_MON_GET_WIN(monitor)
int monitor;
{
int i;
static int last_used;
for (i = 0; i < Windows_Used; i++) {
if ( ! window[i].used ) {
window[i].used = 1;
window[i].monitor = monitor;
last_used = i;
return i;
}
}
return -1;
}
static void CWK_MAKE_WINDOW(title, win_no)
char *title;
int win_no;
{
window[win_no].w = AVL_MAKE_WINDOW( title, window[win_no].wind_coord.x1,
window[win_no].wind_coord.y1,
window[win_no].wind_coord.x2,
window[win_no].wind_coord.y2,
1, 15 );
}
static void CWK_SAVE_TEXT_POS()
{
text_pos = _gettextposition();
}
static void CWK_RES_TEXT_POS()
{
_settextwindow(2,2,ROWS,79);
_settextposition(text_pos.row, text_pos.col);
}
MON_REC_PTR CWK_CREATE_MON_WIN( title, display )
char *title;
int display;
{
CWK_SAVE_TEXT_POS();
CWK_MONS[next_monitor].title = malloc( strlen( title ) + 1 );
strcpy( CWK_MONS[next_monitor].title, title );
if ( display )
{
CWK_MONS[next_monitor].mon_win = CWK_MON_GET_WIN(next_monitor);
if (CWK_MONS[next_monitor].mon_win == -1)
{
CWK_MONS[next_monitor].WON = -1;
}
else
{
CWK_MONS[next_monitor].WON = 1;
CWK_MAKE_WINDOW( title, CWK_MONS[next_monitor].mon_win );
}
}
else
CWK_MONS[next_monitor].WON = -1;
CWK_RES_TEXT_POS();
return &CWK_MONS[next_monitor++];
}
/*************************************************************************/
/* Routines to draw the monitor windows */
/*************************************************************************/
void CWK_REMOVE_BLOCK ( tmp_mon )
MON_REC *tmp_mon;
{
CWK_SAVE_TEXT_POS();
CWK_ERASE_MON_WIN(tmp_mon);
Block_Level--;
if ( Block_Level < 0 )
{
char msg[80];
sprintf( msg, "Internal Error, leaving too many blocks" );
CWK_CLEANUP_MON( -1, msg );
}
*Block_Name[Block_Level] = '\0';
CWK_RES_TEXT_POS();
}
void CWK_DRAW_PROC_WIN( tmp_mon, enter_or_exit )
MON_REC *tmp_mon;
int enter_or_exit;
{
int i, First_Win_On_Screen;
CWK_SAVE_TEXT_POS();
if ( ! enter_or_exit )
{
strcpy( Block_Name[Block_Level], tmp_mon->title );
Block_Level++;
}
if ( Block_Level >= Windows_Used )
{
WIN_SIZE = SAVE_WIN_SIZE - Windows_Used;
tmp_mon->mon_win = Windows_Used - 1;
First_Win_On_Screen = Block_Level - Windows_Used;
CWK_ERASE_ALL_MON_WIN();
tmp_mon->WON = 1;
for ( i = 0; i < Windows_Used; ++i )
{
window[i].used = 1;
CWK_MAKE_WINDOW( Block_Name[First_Win_On_Screen+i], i );
}
}
else if ( Block_Level > 0 )
{
WIN_SIZE = SAVE_WIN_SIZE - Block_Level;
tmp_mon->mon_win = Block_Level - 1;
if ( enter_or_exit )
CWK_ERASE_MON_WIN(tmp_mon);
window[Block_Level-1].used = 1;
tmp_mon->WON = 1;
CWK_MAKE_WINDOW( Block_Name[Block_Level-1], Block_Level-1);
}
CWK_RES_TEXT_POS();
/*
Note that we have to redraw the time, otherwise it
doesn't look right.
*/
CWK_REPORT_TIME(Run_Total_Time);
}
void CWK_DRAW_MON_WIN(tmp_mon)
MON_REC *tmp_mon;
{
CWK_SAVE_TEXT_POS();
tmp_mon->mon_win = CWK_MON_GET_WIN(next_monitor);
if (tmp_mon->mon_win == -1)
{
tmp_mon->WON = -1;
}
else
{
tmp_mon->WON = 1;
CWK_MAKE_WINDOW( tmp_mon->title, tmp_mon->mon_win );
}
CWK_RES_TEXT_POS();
}
void CWK_ERASE_ALL_MON_WIN()
{
int i;
CWK_SAVE_TEXT_POS();
for (i = MAX_WINDOWS - 1; i >= 0; i--) {
if ( window[i].used ) {
window[i].used = 0;
window[i].monitor = -1;
CWK_DEL_WINDOW(i);
}
}
CWK_RES_TEXT_POS();
}
void CWK_ERASE_MON_WIN(tmp_mon)
MON_REC *tmp_mon;
{
#if 0
{
char msg[80];
sprintf( msg, " in erase_mon_win, name = %s, used =%d\n",
tmp_mon->title, window[tmp_mon->mon_win].used );
_outtext(msg);